package testing;

import processing.core.*;
import processing.xml.*;

import java.applet.*;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.MouseEvent;
import java.awt.event.KeyEvent;
import java.awt.event.FocusEvent;
import java.awt.Image;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;

public class readFile{

	/**
	 * LoadFile 1
	 * 
	 * Loads a text file that contains two numbers separated by a tab ('\t'). A
	 * new pair of numbers is loaded each frame and used to draw a point on the
	 * screen.
	 */
    PApplet parent;
	String filename = null;
	public String[] lines;
 
	public readFile(PApplet p){
		this.parent = p;
	}

	public void setup(String f) {
		this.filename = f;
	}
	
	public boolean load(){
		if(filename == null){
			return false;
		}
		lines = parent.loadStrings(filename);
		if(lines.length == 0)
		{
			return false;
		}else{
			return true;
		}
	}
	
	public int getLength(){
		
		if(lines.length == 0){
			load();
		}
		return lines.length;
	}
	
	public int getPieceNum(){
		int piecenum = 0;
		if(lines.length != 0){
			String[] pieces = parent.split(lines[0], '\t');
			piecenum = pieces.length;
		}
		return piecenum;
	}
	
		/**
		if (index < lines.length) {
			String[] pieces = split(lines[index], '\t');
			if (pieces.length == 2) {
				String s = pieces[0];
				int y = PApplet.parseInt(pieces[1]);			
				System.out.println("this line is:"+s+" the number is:"+y);
			}
			// Go to the next line for the next run through draw()
			index = index + 1;
		}
		*/
	

}
